# -*- coding: UTF-8 -*-
import smtplib

from email.mime.text import  MIMEText
from email.header import Header

# 第三方 SMTP 服务
mail_host="smtp.126.com"  #设置服务器
mail_user="lumiachan@126.com"    #用户名
mail_pass="cz16899199"   #口令

sender="lumiachan@126.com";
receive="710474131@qq.com";

message=MIMEText("python测试","plain","utf-8");
message['from']=Header("早上好","utf-8");
message['to']=Header("下午好","utf-8");
subject="邮件测试";
message['Subject']=Header(subject,"utf-8");

try:
    smtpObj=smtplib.SMTP();
    smtpObj.connect(mail_host,25);
    smtpObj.login(mail_user,mail_pass);
    smtpObj.sendmail(sender,receive,message.as_string());
    print("邮件发送成功!");
except smtplib.SMTPException:
    print("邮件发送失败!");
